// 侦测颜色
const zcColors = function () {
    let h, l, s
    const colors = []
    for (let i = 239; i >= 0; i--) {
      h = i * 1.5 + 180
      if (h >= 360) {
        h = h - 360
      }
  
      l = (i / 3 + 40) * 1 / 240
      s = 1.0
      // let col = new RGBColor();
      // console.log(h, s, l);
      // col.SetHSL(h / 360.0, s, l);
      const col = HSL2RGB(h, s, l)
      colors.push(col)
    }
    //   console.log(colors)
    return colors
  }
  const zcColors2 = function () {
    const colors = []
    for (let i = 0; i < 52; i++) {
      const col = new RGBColor()
      col.R = 1,
      col.G = (26 - i / 2)
      col.B = (26 + (i + 1) / 2)
      colors.push(col)
    }
    for (let i = 52; i < 112; i++) {
      const col = new RGBColor()
      col.R = (2 + (i - 52) * 2.2)
      col.G = 2
      col.B = (52 + (i - 52) * 1.5)
      colors.push(col)
    }
    for (let i = 112; i < 166; i++) {
      const col = new RGBColor()
      col.R = (131 + (i - 111) * 2.25)
      col.G = 3
      col.B = (140 - (i - 111) * 2.45)
      colors.push(col)
    }
    for (let i = 166; i < 256; i++) {
      const col = new RGBColor()
      col.R = 252
      col.R = (3 + (i - 165) * 6) > 254 ? 254 : (3 + (i - 165) * 6)
      col.R = (7 + (i - 165) * 2.7)
      colors.push(col)
    }
    const result = []
    for (let i = 255; i >= 0; i--) {
      result.push(colors[i])
    }
    return result
  }
  // 测向色带
  const dirColors = function () {
    let h, l, s
    const colors = []
    for (let i = 0; i < 240; i++) {
      h = i * 1.5 + 180
      if (h >= 360) {
        h = h - 360
      }
      l = 0.5
      s = 1.0
      const col = HSL2RGB(h, s, l)
      // col.SetHSL(h / 360, s, l);
      colors.push(col)
    }
    return colors
  }
  
  // 测向色带的反向
  const dirReverseColors = function () {
    let h, l, s
    const colors = []
    for (let i = 239; i >= 0; i--) {
      h = i * 1.5 + 180
      if (h >= 360) {
        h = h - 360
      }
      l = 0.5
      s = 1.0
      const col = HSL2RGB(h, s, l)
      // col.SetHSL(h / 360, s, l);
      colors.push(col)
    }
    return colors
  }
  
  const blackColors = function () {
    const colors = []
    for (let i = 239; i >= 0; i--) {
      const col = new RGBColor()
      col.R = 255 * i / 240,
      col.G = 255 * i / 240,
      col.B = 255 * i / 240,
      colors.push(col)
    }
    return colors
  }
  
  const sixColors = function () {
    const colors = []
    const tmpcolors = [
      { r: 255, g: 0, b: 0 },
      { r: 255, g: 255, b: 0 },
      { r: 0, g: 255, b: 255 },
      { r: 0, g: 0, b: 255 },
      { r: 0, g: 0, b: 0 }
    ]
    for (let i = 0; i < 640; i++) {
      const col = new RGBColor()
      const tmpIdx = Math.floor(i / 160)
      const percent = (i % 160) / 160
      col.R = tmpcolors[tmpIdx].r + (tmpcolors[tmpIdx + 1].r - tmpcolors[tmpIdx].r) * percent
      col.G = tmpcolors[tmpIdx].g + (tmpcolors[tmpIdx + 1].g - tmpcolors[tmpIdx].g) * percent
      col.B = tmpcolors[tmpIdx].b + (tmpcolors[tmpIdx + 1].b - tmpcolors[tmpIdx].b) * percent
      colors.push(col)
    }
    return colors
  }
  
  function HSL2RGB (h, s, l) {
    let p = 0
    let q = 0
    if (l <= 0.5) {
      q = l * (1 + s)
    } else {
      q = l + s - l * s
    }
    p = 2 * l - q
    const b = rgb(p, q, h - 120)
    const g = rgb(p, q, h)
    const r = rgb(p, q, h + 120)
    const col = new RGBColor()
    col.R = r
    col.G = g
    col.B = b
    return col
  }
  function rgb (p, q, hue) {
    if (hue > 360) {
      hue = hue - 360
    }
    if (hue < 0) {
      hue = hue + 360
    }
    hue = hue / 360
    if (hue * 6 < 1) {
      return (p + (q - p) * 6 * hue) * 255
    }
    if (hue * 2 < 1) {
      return q * 255
    }
    if (hue * 3 < 2) {
      return (p + (q - p) * ((2.0 / 3.0) - hue) * 6.0) * 255
    }
    return p * 255
  }
  export default {
    zcColors: zcColors,
    dirColors: dirColors,
    dirReverseColors: dirReverseColors,
    blackColors: blackColors,
    sixColors: sixColors
  }
  